package com.day9.test2_arr_maopao;

/**
 * @author 小坡
 * @date 2022/9/12  13:58
 **/
public class MyBubbleSort {
    public static void main(String[] args) {
        int[] arr = {111, 5, 3, 1, 110, 0};
//        冒泡排序  0  1  5   6  110  111
//        一共五轮
//        在这里  length-1  是为了不让索引超出范围
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = temp;
            }
        }
        extracted(arr);
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = temp;
            }
        }
        extracted(arr);
        for (int i = 0; i < arr.length - 1 - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = temp;
            }
        }
        extracted(arr);
        for (int i = 0; i < arr.length - 1 - 1 - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = temp;
            }
        }
        extracted(arr);
        for (int i = 0; i < arr.length - 1 - 1 - 1 - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = temp;
            }
        }
        extracted(arr);
    }

    private static void extracted(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "   ");
        }
        System.out.println();
    }
}
